package com.aixin.csopequity.repository;


import com.aixin.csopequity.domain.EquityLevelDef;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EquityLevelRepository extends JpaRepository<EquityLevelDef,Long> {

    @Query(value = "SELECT * FROM equityleveldef where 1 = 1  " +
            "ANd (:equityID is null or equityID = :equityID)",nativeQuery = true)
    List<EquityLevelDef> getEquityLevel(@Param("equityID") String equityID);

    @Modifying
    @Query(value = "UPDATE  equityleveldef  SET equityLevelName = :equityLevelName," +
            " equityLevelRemarks= :equityLevelRemarks, equityLevel = :equityLevel "
            + " where equityLevelID = :equityLevelID" ,nativeQuery = true)
    int updateEquityLevel(@Param("equityLevelName") String equityLevelName,
                          @Param("equityLevelRemarks") String equityLevelRemarks,
                          @Param("equityLevel") int equityLevel,
                          @Param("equityLevelID") String equityLevelID);

    Integer deleteByEquityLevelID(String levelID);

    Integer deleteAllByEquityID(String equityID);
}
